package com.gxa.controller.commserve;

import com.gxa.common.utils.Result;
import com.gxa.dto.commservedto.ComplaintsSuggestionsSearchCriteria;
import com.gxa.service.commserve.ComplaintsSuggestionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:18:00
 */
@Api(tags = "投诉建议")
@RestController
@RequestMapping("/complaints-suggestions")
public class ComplaintsSuggestionsController {
    @Autowired
    private ComplaintsSuggestionsService complaintsSuggestionsService;

//    List<ComplaintsSuggestions> complaintsSuggestionsList;
//    Date date = new Date("2022/10/11");
//
//    public ComplaintsSuggestionsController(){this.init();}
//    public void init(){
//        this.complaintsSuggestionsList = new ArrayList<>();
//        ComplaintsSuggestions complaintsSuggestions = new ComplaintsSuggestions(1,"卫生投诉","第三方的规划法规和地方更丰富",date,0,"张三","12345678910",0);
//        complaintsSuggestionsList.add(complaintsSuggestions);
//        ComplaintsSuggestions complaintsSuggestions1 = new ComplaintsSuggestions(2,"卫生投诉","第三方的规划法规和地方更丰富",date,0,"张三","12345678910",0);
//        complaintsSuggestionsList.add(complaintsSuggestions1);
//    }

    @CrossOrigin(origins = "*",maxAge = 3600)//跨域请求配置
    @ApiOperation(value = "查询投诉建议")
    @GetMapping("list/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
        try {
            Map<String, Object> map = this.complaintsSuggestionsService.queryList(pageNum, pageSize);
            return Result.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("查询失败");
        }
    }

    @CrossOrigin(origins = "*",maxAge = 3600)//跨域请求配置
    @ApiOperation(value = "查询当前用户建议")
    @PostMapping("search")
    public Result search(@RequestBody ComplaintsSuggestionsSearchCriteria complaintsSuggestionsSearchCriteria, Integer pageNum, Integer pageSize){
        try {
            Map<String, Object> map = this.complaintsSuggestionsService.queryListBySearch(complaintsSuggestionsSearchCriteria, pageNum, pageSize);
            return Result.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("当前用户查询失败");
        }
    }


}
